<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="90px" :disabled="disabled">
                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>
                <el-form-item label="加入用户:" prop="user_id">
                    <el-input-number v-model="form.user_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="用户昵称:" prop="nickname">
                    <el-input v-model="form.nickname" placeholder="请输入用户昵称" clearable />
                </el-form-item>
                <el-form-item label="用户头像:" prop="avatar">
                    <el-input v-model="form.avatar" placeholder="请输入用户头像" clearable />
                </el-form-item>
                <el-form-item label="加入房间:" prop="roomId">
                    <el-input-number v-model="form.roomId" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="创建时间:" prop="createTime">
                    <el-date-picker v-model="form.createTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择创建时间" />
                </el-form-item>

                <el-form-item label="更新时间:" prop="updateTime">
                    <el-date-picker v-model="form.updateTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择更新时间" />
                </el-form-item>

                <el-form-item label="状态:" prop="status">
                    <el-select v-model="form.status" placeholder="请选择状态" clearable>
                        <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="拉黑状态:" prop="blacklist">
                    <el-select v-model="form.blacklist" placeholder="请选择拉黑状态" clearable>
                        <el-option v-for="(item, index) in blacklist" :key="index" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="拉黑时间:" prop="blacklist_time">
                    <el-date-picker v-model="form.blacklist_time" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择拉黑时间" />
                </el-form-item>

                <el-form-item label="退房时间:" prop="outTime">
                    <el-date-picker v-model="form.outTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择退房时间" />
                </el-form-item>

                <el-form-item label="角色:" prop="userType">
                    <el-select v-model="form.userType" placeholder="请选择角色" clearable>
                        <el-option v-for="(item, index) in userType" :key="index" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="总用户数:" prop="userCount">
                    <el-input-number v-model="form.userCount" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="在线用户数:" prop="onlineCount">
                    <el-input-number v-model="form.onlineCount" :step="1" :min="0"></el-input-number>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>

<script>
import { regionData } from 'element-china-area-data'
export default {
    name: 'EditForm',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {
                user_id: [{ required: true, message: "请输入加入用户", trigger: "blur" }],
                roomId: [{ required: true, message: "请输入加入房间", trigger: "blur" }],
                status: [{ required: true, message: "请输入状态", trigger: "blur" }],

            },
            form: {  },
            // 区域选择配置
            areaOptions: regionData,
            status:[
               { label: "在房间", value: 1 },
               { label: "不在房间", value: 2 },
            ],
            blacklist:[
               { label: "已拉黑", value: 1 },
               { label: "未拉黑", value: 2 },
            ],
            userType:[
               { label: "普通用户", value: 1 },
               { label: "房主", value: 2 },
            ],

        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },

        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },

        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
